import { useEffect, useMemo, useState } from 'react'
import './index.scss'
import NavBar from '../../extract/index'
import axios from '../../api/index'
import { useParams, useSearchParams } from 'react-router-dom';

type DiseaseData = {
  pathology?: string
  symptom?: string
  benefitTaboo?: string
  westernMedicineTreatment?: string
  chineseMedicineTreatment?: string
}

function Bzxq() {
    const { id } = useParams();
    const [data, setData] = useState<DiseaseData>({})
    const [name] = useSearchParams();
    const nameSpj = useMemo(() => Object.fromEntries(name), [name])
    
    useEffect(() => {
        axios.get('/share/knowledgeBase/v1/findDiseaseKnowledge', {
            params: {
                id: id
            }
        }).then(res => {
            console.log(res);
            setData(res.data.result)
        })
    }, [id])
    
    return (
        <div className='bzxq'>
            <div>
                <NavBar></NavBar>
            </div>
            <div className='mk'>
                <span className='mk-list'>本模块知识仅供参考，如有需要，请在医生指导下使用</span>
            </div>
            <div className='zzxq'>
                <h3 className='bt'>{nameSpj.title}</h3>
                <p className='yyjy'>[病理]</p>
                <p className='jyxq'>{data.pathology ? <span>{data.pathology}</span> : <span>暂无</span>}</p>
                <p className='yyjy'>[症状]</p>
                <p className='jyxq'>{data.symptom ? <span>{data.symptom}</span> : <span>暂无</span>}</p>
                <p className='yyjy'>[宜与忌]</p>
                <p className='jyxq'>{data.benefitTaboo ? <span>{data.benefitTaboo}</span> : <span>暂无</span>}</p>
                <p className='yyjy'>[西药治疗]</p>
                <p className='jyxq'>{data.westernMedicineTreatment ? <span>{data.westernMedicineTreatment}</span> : <span>暂无</span>}</p>
                <p className='yyjy'>[中药治疗]</p>
                <p className='jyxq'>{data.chineseMedicineTreatment ? <span>{data.chineseMedicineTreatment}</span> : <span>暂无</span>}</p>
            </div>
        </div>
    )
}

export default Bzxq